USE master;
GO

-- process a return value with DBCC CHECKDB
BEGIN TRY
	DECLARE @ReturnValue INT;
	EXECUTE @ReturnValue = sp_executesql N'DBCC CHECKDB(''<database_name>'')';
	IF @ReturnValue <> 0
		RAISERROR ('Database corruption detected', 11, 1);
END TRY
BEGIN CATCH
	SELECT
		ERROR_NUMBER() AS ErrorNumber,
		ERROR_SEVERITY() AS ErrorSeverity,
		ERROR_STATE() AS ErrorState,
		ERROR_PROCEDURE() AS ErrorProcedure,
		ERROR_LINE() AS ErrorLine,
		ERROR_MESSAGE() AS ErrorMessage;
END CATCH

-- check the physical integrity of all user databases
EXECUTE dbo.DatabaseIntegrityCheck
@Databases = 'USER_DATABASES',
@CheckCommands = 'CHECKDB',
@PhysicalOnly = 'Y',
@MaxDOP = 4;